/************************************************************************
 * @file PluginActivator.h
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#ifndef PLUGINACTIVATOR_H
#define PLUGINACTIVATOR_H

#include <vector>
#include <map>

using namespace std;

#include <QStringList>

#include <plugin/plugin_global.h>
#include <plugin/command/AbstractCommand.h>

namespace antu
{
namespace plugin
{
class AbstractPlugin;
class PluginContext;
class ServiceRegistry;
class StatusEventListener;

class PLUGINSHARED_EXPORT PluginActivator
{
public:
    PluginActivator();
    PluginActivator(PluginContext* pContext);
    virtual ~PluginActivator();

    virtual void init(QObject* pParent, StatusEventListener* pListener = nullptr);
    virtual void init(const QStringList& plugins, QObject* pParent, StatusEventListener* pListener = nullptr);
    virtual void start(StatusEventListener* pListener = nullptr, bool isRootActivator = false);
    virtual void finishStartup(StatusEventListener* pListener = nullptr);
    virtual void stop(StatusEventListener* pListener = nullptr);

    AbstractCommand::CommandReturnType execute(const QString& commandLine, CommandParameters& outputs);
    AbstractCommand::CommandReturnType execute(const QString& pluginCode,
                                               const QString& serviceName,
                                               const QString& commandName,
                                               const CommandParameters& inputs,
                                               CommandParameters& outputs);

protected:
    PluginContext* m_pPluginContext;
    ServiceRegistry* m_pServiceRegistry;
    vector<AbstractPlugin*> m_oPlugins;
    map<QString, AbstractPlugin*> m_oSortedPlugins;
};
}
}

#endif // PLUGINACTIVATOR_H
